<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<title>Gwack Admin</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<body>
<div id="container">
<?php include ("menu.php");?>

<?php
   if(isset($_POST['submit_x']))
    {
    //Collecting Variables while cancelling out variables received from XML file (this whole section should only happen if the user clicked Save.


		$configfile='/etc/opt/gwack/gwack.xml';

        $xml = simplexml_load_file($configfile) or die("load config failed");

        $name = $_POST['name'];
        $ipaddr = $_POST['ipaddr'];
        $remotepath = $_POST['remotepath'];
        $remoteuser = $_POST['remoteuser'];
        $remotepass = $_POST['remotepass'];
        $mounttype = $_POST['mounttype'];
        $type = $_POST['type'];


        //Create array of xml tags with data

        $newserver['type'] = $type;
        $newserver['ipaddr'] = $ipaddr;
        $newserver['name'] = $name;
        $newserver['remotepath'] = $remotepath;
        $newserver['remoteuser'] = $remoteuser;
        $newserver['remotepass'] = $remotepass;
        $newserver['mounttype'] = $mounttype;
        $newserver['basepath'] = '';
        $newserver['currentfulldate'] = '';
        $newserver['currentfullpath'] = '';
        $newserver['restorepath'] = '';
        $newserver['starttime'] = '';
        $newserver['endtime'] = '';

		if ($type == 'po')
        {
            $newserver['currentinc'] = '';
            $newserver['oldfullpath'] = '';
        }

     	$server = $xml->addChild('server');
        foreach ($newserver as $key=>$value)
        {
			$server->addChild($key, $value);
        }
		$dom = new DOMDocument(1.0) or die("new domdoc");
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadXML($xml->asXML()) or die("why");
        $dom->save($configfile) or die("Can't save config");
		header("Location:settings.php");
    }


?>



  <div id="content">
        <div id="leftBox">
        <div class="contentBox">
            <div class="contentBoxTop">
              <h3>Add New Domain or Post Office</h3>
            </div>
            <div class="innerContent">
                <form name="form1" method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
                <table class="sTable">
                <tr><td class="firstCol">GroupWise Component</td>
                <td class="secondCol">Domain<input type='radio' value='domain' name='type' />
                Post Office<input type='radio' value='po' name='type' /></td></tr>
                <tr><td><b>Name: </b></td>
                <td><input type="text" name="name" /></td></tr>
                <tr><td><b>IP Address: </b></td>
                <td> <input type="text" name="ipaddr" /></td></tr>
                <tr><td><b>Remote Path: </b></td>
                <td><input type="text" name="remotepath" /></td></tr>
                <tr><td><b>Remote User: </b></td>
                <td><input type="text" name="remoteuser" /></td></tr>
                <tr><td><b>Remote Password: </b></td>
                <td><input type="password" name="remotepass" /></td></tr>
                <tr><td><b>Mount Type: </b></td>
                <td>Samba<input type='radio' value='Samba' name='mounttype'
                <?php if ($settings[mounttype] == "samba" or $settings[mounttype] == "Samba") echo 'checked';?> >
                NCP<input type='radio' value='NCP' name='mounttype'
                <?php if ($settings[mounttype] == "NCP") echo 'checked';?> ></td></tr>

                </table>
                <br>
                <input type="image" name="submit" src="images/save.jpg" />
                </form>
                <br>

</div>
</div>
</div>
</div>

<?php include('footer.html');?>
</body>
</html>
